package com.dai.yygh.common.exception;

import com.dai.yygh.common.result.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result doException(Exception exception){
        exception.printStackTrace();
        return Result.fail();
    }


    //自定义异常 因为不是系统的，所以需要手动抛出
    @ExceptionHandler(YyghException.class)
    @ResponseBody
    public Result doException(YyghException e){
        e.printStackTrace();
        return Result.fail();
    }
}
